package com.example.test_ali

import io.flutter.embedding.android.FlutterActivity
import com.alibabacloud.rum.AlibabaCloudRum;

class MainActivity: FlutterActivity(){
    private val CHANNEL = "com.test.sentry"

    override fun configureFlutterEngine(flutterEngine: io.flutter.embedding.engine.FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)
        AlibabaCloudRum.withAppID("gt4la9x12a@c5ccabd3f65f550") // AppID，步骤一创建RUM应用时获取。
      .withConfigAddress("https://gt4la9x12a-default-cn.rum.aliyuncs.com/RUM/config") // ConfigAddress，步骤一创建RUM应用时获取。
      .start(getApplicationContext());
        MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
            if (call.method == "testThrow") {
                try {
                    testError()
                    result.success("error")
                } catch (e: Exception) {
                    result.error("ERROR", "Array index out of bounds", e.localizedMessage)
                }
            } else {
                result.notImplemented()
            }
        }
    }

    private fun testError() {
        val array = arrayOf(1, 2, 3)
        // 模拟数组越界，抛出异常
        println(array[5])
    }
}
